package com.newcapec.modules.oss.cloud;

import com.newcapec.common.utils.ConfigConstant;
import com.newcapec.common.utils.Constant;
import com.newcapec.common.utils.SpringContextUtils;
import com.newcapec.modules.sys.service.SysConfigService;

/**
 * 文件上传Factory
 *
 * @author steven
 */
public final class OSSFactory {
    private static SysConfigService sysConfigService;

    static {
        OSSFactory.sysConfigService = (SysConfigService) SpringContextUtils.getBean("sysConfigService");
    }

    public static CloudStorageService build(){
        //获取云存储配置信息
        CloudStorageConfig config = sysConfigService.getConfigObject(ConfigConstant.CLOUD_STORAGE_CONFIG_KEY, CloudStorageConfig.class);

        if(config.getType() == Constant.CloudService.MINIO.getValue()){
            return new MinioCloudStorageService(config);
        }else if(config.getType() == Constant.CloudService.QINIU.getValue()){
            return new QiniuCloudStorageService(config);
        }else if(config.getType() == Constant.CloudService.ALIYUN.getValue()){
            return new AliyunCloudStorageService(config);
        }else if(config.getType() == Constant.CloudService.QCLOUD.getValue()){
            return new QcloudCloudStorageService(config);
        }
        return null;
    }

    public static String getOssDomain(){
        //获取云存储配置信息
        CloudStorageConfig config = sysConfigService.getConfigObject(ConfigConstant.CLOUD_STORAGE_CONFIG_KEY, CloudStorageConfig.class);

        if(config.getType() == Constant.CloudService.MINIO.getValue()){
            return config.getMinioDomain();
        }else if(config.getType() == Constant.CloudService.QINIU.getValue()){
            return config.getQiniuDomain();
        }else if(config.getType() == Constant.CloudService.ALIYUN.getValue()){
            return config.getAliyunDomain();
        }else if(config.getType() == Constant.CloudService.QCLOUD.getValue()){
            return config.getQcloudDomain();
        }
        return "";
    }
}
